<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="用户手机id">
            <el-input v-model="form.smsPhoneId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="用户token" prop="smsUserToken">
            <el-input v-model="form.smsUserToken" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="手机token" prop="smsPhoneToken">
            <el-input v-model="form.smsPhoneToken" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="平台token" prop="smsPlatformToken">
            <el-input v-model="form.smsPlatformToken" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="手机号" prop="smsPhoneNumber">
            <el-input v-model="form.smsPhoneNumber" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="手机号平台key" prop="smsPhoneKey">
            <el-input v-model="form.smsPhoneKey" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="手机号提取时间" prop="smsPhoneCreateTime">
            <el-input v-model="form.smsPhoneCreateTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="归属国家代码" prop="smsPhoneCountryCode">
            <el-input v-model="form.smsPhoneCountryCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="归属区域代码" prop="smsPhoneAreaCode">
            <el-input v-model="form.smsPhoneAreaCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="归属地" prop="smsPhonePosition">
            <el-input v-model="form.smsPhonePosition" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="端口号" prop="smsPhonePort">
            <el-input v-model="form.smsPhonePort" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="对接码" prop="smsPhoneAcceptCode">
            <el-input v-model="form.smsPhoneAcceptCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="状态码" prop="smsPhoneStatus">
            <el-input v-model="form.smsPhoneStatus" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="原始值" prop="smsOriginal">
            <el-input v-model="form.smsOriginal" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="更新时间">
            <el-input v-model="form.smsPhoneUpdateTime" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="smsPhoneId" label="用户手机id" />
        <el-table-column prop="smsUserToken" label="用户token" />
        <el-table-column prop="smsPhoneToken" label="手机token" />
        <el-table-column prop="smsPlatformToken" label="平台token" />
        <el-table-column prop="smsPhoneNumber" label="手机号" />
        <el-table-column prop="smsPhoneKey" label="手机号平台key" />
        <el-table-column prop="smsPhoneCreateTime" label="手机号提取时间" />
        <el-table-column prop="smsPhoneCountryCode" label="归属国家代码" />
        <el-table-column prop="smsPhoneAreaCode" label="归属区域代码" />
        <el-table-column prop="smsPhonePosition" label="归属地" />
        <el-table-column prop="smsPhonePort" label="端口号" />
        <el-table-column prop="smsPhoneAcceptCode" label="对接码" />
        <el-table-column prop="smsPhoneStatus" label="状态码" />
        <el-table-column prop="smsOriginal" label="原始值" />
        <el-table-column prop="smsPhoneUpdateTime" label="更新时间" />
        <el-table-column v-if="checkPer(['admin','smsPhone:edit','smsPhone:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudSmsPhone from '@/api/smsPhone'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { smsPhoneId: null, smsUserToken: null, smsPhoneToken: null, smsPlatformToken: null, smsPhoneNumber: null, smsPhoneKey: null, smsPhoneCreateTime: null, smsPhoneCountryCode: null, smsPhoneAreaCode: null, smsPhonePosition: null, smsPhonePort: null, smsPhoneAcceptCode: null, smsPhoneStatus: null, smsOriginal: null, smsPhoneUpdateTime: null }
export default {
  name: 'SmsPhone',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '短信手机', url: 'api/smsPhone', idField: 'smsPhoneId', sort: 'smsPhoneId,desc', crudMethod: { ...crudSmsPhone }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'smsPhone:add'],
        edit: ['admin', 'smsPhone:edit'],
        del: ['admin', 'smsPhone:del']
      },
      rules: {
        smsUserToken: [
          { required: true, message: '用户token不能为空', trigger: 'blur' }
        ],
        smsPhoneToken: [
          { required: true, message: '手机token不能为空', trigger: 'blur' }
        ],
        smsPlatformToken: [
          { required: true, message: '平台token不能为空', trigger: 'blur' }
        ],
        smsPhoneNumber: [
          { required: true, message: '手机号不能为空', trigger: 'blur' }
        ],
        smsPhoneKey: [
          { required: true, message: '手机号平台key不能为空', trigger: 'blur' }
        ],
        smsPhoneCreateTime: [
          { required: true, message: '手机号提取时间不能为空', trigger: 'blur' }
        ],
        smsPhoneCountryCode: [
          { required: true, message: '归属国家代码不能为空', trigger: 'blur' }
        ],
        smsPhoneAreaCode: [
          { required: true, message: '归属区域代码不能为空', trigger: 'blur' }
        ],
        smsPhonePosition: [
          { required: true, message: '归属地不能为空', trigger: 'blur' }
        ],
        smsPhonePort: [
          { required: true, message: '端口号不能为空', trigger: 'blur' }
        ],
        smsPhoneAcceptCode: [
          { required: true, message: '对接码不能为空', trigger: 'blur' }
        ],
        smsPhoneStatus: [
          { required: true, message: '状态码不能为空', trigger: 'blur' }
        ],
        smsOriginal: [
          { required: true, message: '原始值不能为空', trigger: 'blur' }
        ]
      }}
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
